<?php

/**
 * This file is part of the Pagizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Pagizer Core Team <team@pagizer.org>
 * @package     pagizer
 * @subpackage  medias
 */

class m_medias_actions_block_GenerateThumbAction extends m_backoffice_extends_FormModal
{
	public function execute()
	{      
        if($this->isFormSubmit())
        {
            $parameters = m_medias_services_ParameterService::getInstance()->getParametersByFolderId($this->getRequestParameter("docId"), $this->getRequestParameter("docLang"));

            if(!is_null($parameters))
            {
                $folder = $this->getDocumentFromRequest();
                $medias = $folder->getMedia();

                foreach($medias as $media)
                {
                    /* @var $parameter m_medias_documents_Parameter */
                    foreach($parameters as $parameter)
                    {
                        if($parameter->isGenerateOnUpload())
                        {
                            $media->advancedResizePicture($parameter->getWidth(), $parameter->getHeight(), $parameter->getCrop());
                        }
                    }
                }
            }

            $this->closeModalAndRefresh();
        }

        $this->setModalParameters();
        $this->setView('success');
	}	
}